﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar.Common;

namespace SLControlLibrary.Resources.Controls.Calendar.Buttons
{
    public class ucGuideButton : Button
    {
        #region Dependency Variables
        private static DependencyProperty ButtonTypeProperty = DependencyProperty.Register("ButtonType", typeof(Enumerations.GuideButtonType), typeof(ucGuideButton), new PropertyMetadata(Enumerations.GuideButtonType.Day, new PropertyChangedCallback(ButtonType_Changed)));
        private static DependencyProperty ButtonTextProperty = DependencyProperty.Register("ButtonText", typeof(string), typeof(ucGuideButton), new PropertyMetadata("Day"));
        private static DependencyProperty ButtonIsPressedProperty = DependencyProperty.Register("ButtonIsPressed", typeof(bool), typeof(ucGuideButton), new PropertyMetadata(false, new PropertyChangedCallback(ButtonIsPressed_Changed)));
        #endregion

        #region Dependency Properties
        public Enumerations.GuideButtonType ButtonType
        {
            get { return (Enumerations.GuideButtonType)this.GetValue(ButtonTypeProperty); }
            set { this.SetValue(ButtonTypeProperty, value); }
        }
        public string ButtonText
        {
            get { return this.GetValue(ButtonTextProperty).ToString(); }
            set { this.SetValue(ButtonTextProperty, value); }
        }
        public bool ButtonIsPressed
        {
            get { return (bool)GetValue(ButtonIsPressedProperty); }
            set { SetValue(ButtonIsPressedProperty, value); }
        }
        #endregion

        #region Constructor
        public ucGuideButton()
        {
            DefaultStyleKey = typeof(ucGuideButton);
        }
        #endregion

        #region Events
        #region OnMouseLeave
        protected override void OnMouseLeave(MouseEventArgs e)
        {
            UpdateVisualState();
        }
        #endregion

        #region ButtonType_Changed
        private static void ButtonType_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ucGuideButton cal = (ucGuideButton)sender;
            cal.ButtonText = cal.ButtonType.ToString();
        }
        #endregion

        #region ButtonIsPressed_Changed
        private static void ButtonIsPressed_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ucGuideButton cal = (ucGuideButton)sender;
            cal.ButtonIsPressed = (bool)e.NewValue;
            cal.IsPressed = (bool)e.NewValue;
            cal.UpdateVisualState();
        }
        #endregion
        #endregion

        #region Methods
        #region UpdateVisualState
        private void UpdateVisualState()
        {
            if (ButtonIsPressed)
                VisualStateManager.GoToState(this, "Pressed", true);
            else
                VisualStateManager.GoToState(this, "Normal", true);
        }
        #endregion
        #endregion
    }
}
